package main

import "fmt"

type User struct {
	username string
	password string
}

func main() {

	// 创建一个新的结构体
	user := User{"admin", "123456"}
	fmt.Println(user)

	// 也可以使用 key => value 格式
	user1 := User{username: "test", password: "345678"}
	fmt.Println(user1)
	fmt.Println(user1.username)
	fmt.Println(user1.password)

	// 忽略的字段为 0 或 空
	user3 := User{username: "Go 语言"}
	fmt.Println(user3)
	fmt.Println(user3.password)

	var pointer = &user
	fmt.Printf("%x\n", pointer)
	fmt.Println(*pointer)

	var numbers []int

	printSlice(numbers)

	if numbers == nil {
		fmt.Printf("切片是空的\n")
	}
	numbers = []int{0, 1, 2, 3, 4, 5, 6, 7, 8}
	printSlice(numbers)
	/* 打印子切片从索引1(包含) 到索引4(不包含)*/
	fmt.Println("numbers[1:4] ==", numbers[1:4])
	/* 默认下限为 0*/
	fmt.Println("numbers[:3] ==", numbers[:3])

	/* 默认上限为 len(s)*/
	fmt.Println("numbers[4:] ==", numbers[4:])

	numbers1 := make([]int, 0, 5)
	printSlice(numbers1)

	/* 打印子切片从索引  0(包含) 到索引 2(不包含) */
	number2 := numbers[:2]
	printSlice(number2)

	/* 打印子切片从索引 2(包含) 到索引 5(不包含) */
	number3 := numbers[2:5]
	printSlice(number3)
}

func printSlice(x []int) {
	fmt.Printf("len=%d cap=%d slice=%v\n", len(x), cap(x), x)
}
